{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from snakebite.client import Client     # "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "client = Client(\"hadoop_env.com\", 9000, use_trash=False)  #"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "ls_files=client.ls(['/test_data'])  #"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1568194427743L, 'block_replication': 1, 'modification_time': 1568194428062L, 'length': 4551L, 'blocksize': 134217728L, 'owner': u'root', 'path': '/test_data/iris.data'}\n",
      "{'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1568194133530L, 'block_replication': 1, 'modification_time': 1568194134713L, 'length': 197979L, 'blocksize': 134217728L, 'owner': u'root', 'path': '/test_data/links.csv'}\n",
      "{'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1568194134753L, 'block_replication': 1, 'modification_time': 1568194134812L, 'length': 494431L, 'blocksize': 134217728L, 'owner': u'root', 'path': '/test_data/movies.csv'}\n",
      "{'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1568194134825L, 'block_replication': 1, 'modification_time': 1568194134927L, 'length': 2483723L, 'blocksize': 134217728L, 'owner': u'root', 'path': '/test_data/ratings.csv'}\n",
      "{'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1568194134936L, 'block_replication': 1, 'modification_time': 1568194134965L, 'length': 118660L, 'blocksize': 134217728L, 'owner': u'root', 'path': '/test_data/tags.csv'}\n",
      "{'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1567143893408L, 'block_replication': 1, 'modification_time': 1567143893602L, 'length': 3715L, 'blocksize': 134217728L, 'owner': u'root', 'path': '/test_data/test.csv'}\n"
     ]
    }
   ],
   "source": [
    "for x in ls_files:\n",
    "    print x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'directoryCount': 12L,\n",
       "  'fileCount': 7L,\n",
       "  'length': 3306717L,\n",
       "  'path': '/',\n",
       "  'quota': 9223372036854775807L,\n",
       "  'spaceConsumed': 3306717L,\n",
       "  'spaceQuota': 18446744073709551615L}]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(client.count(['/']))    #"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "mkdirs=client.mkdir(['/temp_data','/201909'],create_parent=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'path': '/temp_data', 'result': True}, {'path': '/201909', 'result': True}]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(mkdirs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "rmdir_res=client.rmdir(['/temp_data'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'path': '/temp_data', 'result': True}]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(rmdir_res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "delete_files=client.delete(['/test_data/temp.py'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'path': '/test_data/temp.py', 'result': True}]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(delete_files)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'capacity': 41083600896L,\n",
       " 'corrupt_blocks': 0L,\n",
       " 'filesystem': 'hdfs://hadoop_env.com:9000',\n",
       " 'missing_blocks': 0L,\n",
       " 'remaining': 26666823680L,\n",
       " 'under_replicated': 0L,\n",
       " 'used': 3439893L}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "client.df()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'access_time': 0L,\n",
       " 'block_replication': 0,\n",
       " 'blocksize': 0L,\n",
       " 'file_type': 'd',\n",
       " 'group': u'supergroup',\n",
       " 'length': 0L,\n",
       " 'modification_time': 1568197308654L,\n",
       " 'owner': u'root',\n",
       " 'path': '/test_data',\n",
       " 'permission': 493}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "client.stat(['/test_data'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "client.test('/201909')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "du_info=client.du(['/test_data'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'length': 4365L, 'path': '/test_data/func.py'},\n",
       " {'length': 4551L, 'path': '/test_data/iris.data'},\n",
       " {'length': 197979L, 'path': '/test_data/links.csv'},\n",
       " {'length': 494431L, 'path': '/test_data/movies.csv'},\n",
       " {'length': 2483723L, 'path': '/test_data/ratings.csv'},\n",
       " {'length': 12099L, 'path': '/test_data/result.txt'},\n",
       " {'length': 118660L, 'path': '/test_data/tags.csv'},\n",
       " {'length': 3715L, 'path': '/test_data/test.csv'}]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(du_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
